package com.bw.day03.change

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.base.net.entity.LoginEntity
import com.bw.base.net.entity.Res
import com.bw.base.net.entity.SendCodeEntity
import com.bw.base.net.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class ChangeViewModel: BaseViewModel() {
    val success= MutableLiveData<Res<Boolean>>()
    val fail= MutableLiveData<String>()
    fun change(account:String,captcha:String,password:String){
        viewModelScope.launch {
            try {
                val  map= mutableMapOf<String,Any>()
                map["account"]=account
                map["captcha"]=captcha
                map["password"]=password
                success.value=apiService.changer(mapToBody(map))
            }catch (e:Exception){
                fail.value=e.message
            }
        }
    }
    val sendSuccess=MutableLiveData<Res<SendCodeEntity>>()
    val sendFail=MutableLiveData<String>()
    fun sendCode(phone:String){
        viewModelScope.launch {
            try {
                sendSuccess.value = apiService.sendCode(phone)
            } catch (e:Exception){
                sendFail.value = e.message
            }

        }
    }

}